<?php
namespace User\Model;

use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\Sql\Select;

class UserTable extends AbstractTableGateway
{
    protected $table = 'users';
    public function __construct(Adapter $adapter)
    {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
        $this->resultSetPrototype->setArrayObjectPrototype(new User());
    
        $this->initialize();
    }
    
    public function fetchAll()
    {
        $resultSet = $this->select();
        return $resultSet;
    }
    public function countAll()
    {
        return $this->select()->count();
    }
    public function getList($offset, $limit)
    {
        $resultSet = $this->select(function(Select $select) use ($limit, $offset) {$select->order('id DESC')->limit($limit)->offset($offset);});

        $array = array();
        foreach ($resultSet as $value) {
            array_push($array, $value);
        }
        return $array;
    }
}